import { Controller } from "../../mvc/core/Controller";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { DataEvent } from "../events/DataEvent";
import { Global } from "../../../com/gengine/global/Global";
import { FlyToNavbarTool } from "../view/award/FlyToNavbarTool";
import { GlobalClass } from "../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../resource/ImagesConst";
import { ItemData } from "../resource/info/ItemData";
import { ItemsUtil } from "../view/shortcuts/item/ItemsUtil";
import { LoaderManager } from "../../../com/gengine/resource/LoaderManager";
import { ImageInfo } from "../../../com/gengine/resource/info/ImageInfo";
import { RolePlayer } from "../scene/player/entity/RolePlayer";
//class FlyEntityController
    
    export  class FlyEntityController extends Controller
    {
       

        protected /* override */ initServer(): void
        {
            Dispatcher.addEventListener(EventName.BackPackAddTaskEntity, this.onBackPackAddTaskEntityHandler);
            Dispatcher.addEventListener(EventName.BackPackFlyGoldToPack, this.flyGoldToPackHandler);
            Dispatcher.addEventListener(EventName.BackPackFlyToPack, this.flyToBackPackHandler);
            return;
        }

        /* internal  */flyGoldToPackHandler(arg1: DataEvent): void
        {
            var loc1=new Object /* flash.geom.Point */(Global.stage.stageWidth / 2, Global.stage.stageHeight / 2);
            if (arg1.data["sPoint"] != null) 
            {
                loc1 = arg1.data["sPoint"] as Object /* flash.geom.Point */;
            }
            FlyToNavbarTool.flyToBackPack(GlobalClass.getBitmapData(ImagesConst.Yuanbao_bind), loc1);
            return;
        }

        /* internal  */flyToBackPackHandler(arg1: DataEvent): void
        {
            var loc2=null;
            if (arg1.data["point"] != null) 
            {
                this._lastCustomPoint = arg1.data["point"];
            }
            var loc1=arg1.data["itemData"] as ItemData;
            loc2 = loc1.itemInfo.item.icon + ".jpg";
            if (ItemsUtil.isCoinBindSundry(loc1)) 
            {
                loc2 = ItemsUtil.CoinIcoUrl;
            }
            LoaderManager.instance.load(loc2, this.onLoaded);
            return;
        }

        /* internal  */onBackPackAddTaskEntityHandler(arg1: DataEvent): void
        {
            var loc2=null;
            var loc1=arg1.data as ItemData;
            loc2 = loc1.itemInfo.item.icon + ".jpg";
            if (ItemsUtil.isCoinBindSundry(loc1)) 
            {
                loc2 = ItemsUtil.CoinIcoUrl;
            }
            LoaderManager.instance.load(loc2, this.onLoaded);
            return;
        }

        /* internal  */onLoaded(arg1: ImageInfo): void
        {
            if (this._lastCustomPoint == null) 
            {
                this._lastCustomPoint = new Object /* flash.geom.Point */(RolePlayer.instance.stagePointX, RolePlayer.instance.stagePointY);
            }
            FlyToNavbarTool.flyToBackPack(arg1.bitmapData, this._lastCustomPoint);
            this._lastCustomPoint = null;
            return;
        }

        private /* var */_lastCustomPoint: Object /* flash.geom.Point */;
    }
